
import 'package:hongsheng/api/SPClassApiManager.dart';
import 'package:hongsheng/api/SPClassHttpCallBack.dart';
import 'package:hongsheng/app/SPClassApplicaion.dart';
import 'package:hongsheng/model/SPClassExpertInfo.dart';
import 'package:hongsheng/model/SPClassSchemeListEntity.dart';
import 'package:hongsheng/pages/common/SPClassNoDataView.dart';
import 'package:hongsheng/pages/expert/SPClassLeaguePage.dart';
import 'package:hongsheng/pages/home/SPClassSchemeItemView.dart';
import 'package:hongsheng/utils/SPClassCommonMethods.dart';
import 'package:hongsheng/utils/SPClassImageUtil.dart';
import 'package:hongsheng/utils/SPClassLogUtils.dart';
import 'package:hongsheng/utils/SPClassMatchDataUtils.dart';
import 'package:hongsheng/utils/SPClassNavigatorUtils.dart';
import 'package:hongsheng/utils/SPClassStringUtils.dart';
import 'package:hongsheng/utils/SPClassToastUtils.dart';
import 'package:hongsheng/utils/colors.dart';
import 'package:hongsheng/utils/common.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:hongsheng/widgets/SPClassBallFooter.dart';
import 'package:hongsheng/widgets/SPClassExpandIcon.dart';
import 'package:hongsheng/widgets/SPClassToolBar.dart';
import 'package:intl/intl.dart';
import 'package:syncfusion_flutter_charts/charts.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';

import 'SPClassExpertLeagueDetail.dart';



class SPClassExpertDetailPage extends StatefulWidget{
  SPClassExpertInfo ?info;
  bool ?spProIsStatics;
  SPClassExpertDetailPage(this.info,{this.spProIsStatics:true});

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return SPClassExpertDetailPageState();
  }

}

class SPClassExpertDetailPageState extends State<SPClassExpertDetailPage> with TickerProviderStateMixin{
  int page=1;
  List<SPClassSchemeListSchemeList> spProSchemeHistory=[];
  List<SPClassSchemeListSchemeList> spProSchemeList=[];
  List<SPClassChartData> spProChartData=[];
  List<int> ?spProDates;
  Container ?spProChartsCon;
  List tabBarList = ['近期状态','命中率','联赛胜率'];
  TabController ?_tabController;
  int index =0;
  List leaguesTimeList = ['近7天','近30天','全周期'];
  String selectTime ='近30天';
  SPClassLeagues ?leagueData;
  String selectLeague='';
  EasyRefreshController spProRefreshController =  EasyRefreshController();


  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    spFunGetRecentReport();
    spFunOnRefreshSelf();
    _tabController = TabController(initialIndex: 0,length: tabBarList.length,vsync: this);
    if(widget.spProIsStatics!){
      SPClassApiManager.spFunGetInstance().spFunLogAppEvent(spProEventName: "view_expert",targetId:widget.info!.spProUserId);
    }


    
  }
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    ///
    return Scaffold(
      appBar: SPClassToolBar(
        context,title: widget.info?.spProNickName??'',spProBgColor: Color(0xFFDE3C31),elevation: 0,iconColor: 0xFFFFFFFF,
      ),
      body: Container(
        color:Color(0xFFF1F1F1),
        child: Stack(
          children: <Widget>[
            Container(
              width: MediaQuery.of(context).size.width,
              height: MediaQuery.of(context).size.height,
              child: Column(
                  children: <Widget>[
                    Container(
                      height: width(60),
                      color: Color(0xFFDE3C31),
                    )
                  ]
              ),
            ),
            Positioned(
              left: 0,right: 0,top: 0,bottom: 0,
                child: Container(
                  width: MediaQuery.of(context).size.width,
                  height: MediaQuery.of(context).size.height,
                  child: EasyRefresh.custom(
                    controller: spProRefreshController,
                    footer: SPClassBallFooter(
                      textColor: Color(0xFF8F8F8F),
                    ),
                    onLoad: spFunOnLoadSelf,
                    slivers: [
                      SliverList(delegate: SliverChildListDelegate([
                        autoInfo(),
                        chartWidget(),
                        expertScheme(),
                      ])),
                      SliverList(
                          delegate:SliverChildListDelegate([
                            Container(
                              margin: EdgeInsets.only(left: width(13),right:  width(13),top:width(8),bottom:width(8) ),
                              decoration: BoxDecoration(
                                color: Colors.white,
                                borderRadius: BorderRadius.circular(width(7)),
                                boxShadow:[
                                  BoxShadow(
                                    offset: Offset(2,5),
                                    color: Color(0x0D000000),
                                    blurRadius:width(6,),),
                                  BoxShadow(
                                    offset: Offset(-5,1),
                                    color: Color(0x0D000000),
                                    blurRadius:width(6,),
                                  )
                                ],
                              ),
                              width: MediaQuery.of(context).size.width,

                              child:spProSchemeHistory.isEmpty?SizedBox(): Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: <Widget>[
                                  Container(
                                    height: height(35),
                                    padding: EdgeInsets.only(left: width(13),right: width(13)),
                                    decoration: BoxDecoration(
                                        border: Border(bottom: BorderSide(width: 0.4,color: Colors.grey[300]!))
                                    ),
                                    child: Row(
                                      children: <Widget>[
                                        Container(
                                          width: height(4),
                                          height: height(14),
                                          decoration: BoxDecoration(
                                              color: Color(0xFFDE3C31),
                                              borderRadius: BorderRadius.circular(100)
                                          ),
                                        ),
                                        SizedBox(width: 4,),
                                        Text("历史推荐",style: TextStyle(fontWeight: FontWeight.w500,fontSize: sp(15)),),

                                      ],
                                    ),
                                  ),
                                  ListView.builder(
                                      physics: NeverScrollableScrollPhysics(),
                                      shrinkWrap: true,
                                      padding: EdgeInsets.only(bottom: width(5)),
                                      itemCount: spProSchemeHistory.length,
                                      itemBuilder: (c,index){
                                        var item=spProSchemeHistory[index];
                                        return Stack(
                                          children: <Widget>[
                                            SPClassSchemeItemView(item,spProShowRate: false,spProShowLine:spProSchemeHistory.length>(index+1),),
                                            Positioned(
                                              top: 10,
                                              right:  width(13) ,
                                              child: Image.asset(
                                                (item.spProIsWin=="1")? SPClassImageUtil.spFunGetImagePath("ic_result_red"):
                                                (item.spProIsWin=="0")? SPClassImageUtil.spFunGetImagePath("ic_result_hei"):
                                                (item.spProIsWin=="2")? SPClassImageUtil.spFunGetImagePath("ic_result_zou"):"",
                                                width: width(40),
                                              ),
                                            ),
                                          ],
                                        );
                                      })
                                ],
                              ),
                            ),
                          ])
                      )
                    ],
                  ),
                ))
          ],
        ),
      ),
    );
  }

  Widget appBarWidget(){
    return Container(
      margin:
      EdgeInsets.only(top: MediaQuery.of(context).padding.top),
      child: Commons.getAppBar(
        title: '专家详情',
        appBarLeft: InkWell(
          child: Image.asset(
            SPClassImageUtil.spFunGetImagePath("arrow_right"),
            width: width(23),
          ),
          onTap: () {
            Navigator.of(context).pop();
          },
        ),
      ),
    );
  }

  Widget autoInfo(){
    return Container(
      margin: EdgeInsets.only(left: width(13),right:  width(13)),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(width(7)),
        boxShadow:[
          BoxShadow(
            offset: Offset(2,5),
            color: Color(0x0D000000),
            blurRadius:width(6,),),
          BoxShadow(
            offset: Offset(-5,1),
            color: Color(0x0D000000),
            blurRadius:width(6,),
          )
        ],
      ),
      width: MediaQuery.of(context).size.width,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Container(
              padding: EdgeInsets.all(width(10)),
              child:Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Flexible(
                        fit: FlexFit.tight,
                        flex: 1,
                        child:Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: <Widget>[
                            Row(
                              children: <Widget>[
                                Container(
                                  decoration: BoxDecoration(
                                      border: Border.all(width: 0.4,color: Colors.grey[200]!),
                                      borderRadius: BorderRadius.circular(width(20))),
                                  child:  ClipRRect(
                                    borderRadius: BorderRadius.circular(width(20)),
                                    child:( widget.info?.spProAvatarUrl==null||widget.info!.spProAvatarUrl!.isEmpty)? Image.asset(
                                      SPClassImageUtil.spFunGetImagePath("ic_default_avater"),
                                      width: width(40),
                                      height: width(40),
                                    ):Image.network(
                                      widget.info?.spProAvatarUrl??'',
                                      width: width(40),
                                      height: width(40),
                                      fit: BoxFit.fill,
                                    ),
                                  ),
                                ),
                                SizedBox(width: width(5),),
                                Expanded(
                                  child: Column(
                                    children: <Widget>[
                                      Row(
                                        children: <Widget>[
                                          Text(widget.info?.spProNickName??'',style: TextStyle(fontSize: sp(14),color: Color(0xFF333333)),maxLines: 1,),
                                          SizedBox(width: 5,),

                                          Visibility(
                                            child: Container(
                                              padding: EdgeInsets.only(left: width(5),right:  width(5),top: width(0.8)),
                                              alignment: Alignment.center,
                                              height: width(16),
                                              constraints: BoxConstraints(
                                                  minWidth: width(52)
                                              ),
                                              decoration: BoxDecoration(
                                                gradient: LinearGradient(
                                                    colors: [Color(0xFFF2150C),Color(0xFFF24B0C)]
                                                ),
                                                borderRadius: BorderRadius.circular(100),
                                              ),
                                              child:Text(("近"+widget.info!.spProLast10Result!.length.toString()+"中"+widget.info!.spProLast10CorrectNum!),
                                                style: TextStyle(fontSize: sp(9),color: Colors.white,letterSpacing: 1),),
                                            ),
                                            visible:  (widget.info!.spProSchemeNum!=null&&(double.tryParse(widget.info!.spProLast10CorrectNum!)!/double.tryParse(widget.info!.spProLast10Result!.length.toString())!)>=0.6),
                                          ),
                                          SizedBox(width: 3,),
                                          int.tryParse( widget.info!.spProCurrentRedNum!)!>2?  Stack(
                                            children: <Widget>[
                                              Image.asset(widget.info!.spProCurrentRedNum!.length>1  ? SPClassImageUtil.spFunGetImagePath("ic_recent_red2"):SPClassImageUtil.spFunGetImagePath("ic_recent_red"),
                                                height:width(16) ,
                                                fit: BoxFit.fitHeight,
                                              ),
                                              Positioned(
                                                left: width(widget.info!.spProCurrentRedNum!.length>1  ? 5:7),
                                                bottom: 0,
                                                top: 0,
                                                child: Container(
                                                  alignment: Alignment.center,
                                                  child: Text(widget.info!.spProCurrentRedNum!,style: TextStyle(color:Color(0xFFDE3C31) ,fontSize: sp(14.8),fontWeight: FontWeight.bold,fontStyle: FontStyle.italic)),
                                                ),
                                              ),
                                              Positioned(
                                                right: width(7),
                                                bottom: 0,
                                                top: 0,
                                                child: Container(
                                                  padding: EdgeInsets.only(top: width(0.8)),

                                                  alignment: Alignment.center,
                                                  child: Text("连红",style: TextStyle(color:Colors.white ,fontSize: sp(9),fontStyle: FontStyle.italic)),
                                                ),
                                              )
                                            ],
                                          ):SizedBox()
                                        ],
                                      ),
                                      Row(children: <Widget>[
                                        Text(SPClassMatchDataUtils.spFunCalcBestCorrectRate(widget.info!.spProLast10Result!)<0.7? "":("近期胜率: "+(SPClassMatchDataUtils.spFunCalcBestCorrectRate(widget.info?.spProLast10Result??'0')*100).toStringAsFixed(0)+"%"),style: TextStyle(fontSize: sp(11),color: Color(0xFFDE3C31)),)
                                      ],)
                                    ],
                                  ),
                                ),

                              ],
                            ),

                          ],
                        ),
                      ),
                      GestureDetector(
                        onTap: (){
                          if(spFunIsLogin(context: context)){
                            SPClassApiManager.spFunGetInstance().spFunFollowExpert(isFollow: ! widget.info!.spProIsFollowing!,spProExpertUid:  widget.info!.spProUserId,context: context,spProCallBack: SPClassHttpCallBack(
                                spProOnSuccess: (result){
                                  if(! widget.info!.spProIsFollowing!){
                                    SPClassToastUtils.spFunShowToast(msg: "关注成功");
                                    widget.info!.spProIsFollowing=true;
                                  }else{
                                    widget.info!.spProIsFollowing=false;
                                  }
                                  if(mounted){
                                    setState(() {});
                                  }
                                },onError: (e){},spProOnProgress: (v){}
                            ));
                          }
                        },
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.center,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: <Widget>[
                            Row(
                              mainAxisAlignment: MainAxisAlignment.end,
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: <Widget>[
                                Container(
                                  decoration: BoxDecoration(
                                    borderRadius: BorderRadius.circular(width(2)),
                                    gradient: LinearGradient(
                                        colors: widget.info!.spProIsFollowing!? [Color(0xFFC6C6C6),Color(0xFFC6C6C6)]:[Color(0xFFF2150C),Color(0xFFF24B0C)]
                                    ),
                                    boxShadow:widget.info!.spProIsFollowing!?null:[
                                      BoxShadow(
                                        offset: Offset(3,3),
                                        color: Color(0x4DF23B0C),
                                        blurRadius:width(5,),),
                                      BoxShadow(
                                        offset: Offset(-2,1),
                                        color: Color(0x4DF23B0C),
                                        blurRadius:width(5,),),
                                    ],
                                  ),
                                  width: width(58),
                                  height: width(20),
                                  child: Row(
                                    mainAxisAlignment: MainAxisAlignment.center,
                                    crossAxisAlignment: CrossAxisAlignment.center,
                                    children: <Widget>[
                                      Icon(widget.info!.spProIsFollowing!? Icons.check:Icons.add,color: Colors.white,size: width(15),),
                                      Text( widget.info!.spProIsFollowing!? "已关注":"关注",style: TextStyle(fontSize: sp(11),color: Colors.white),),

                                    ],
                                  ),
                                ),

                              ],
                            ),
                            SizedBox(height: 5,),
                            // Text("粉丝数: +"widget.spProSchemeDetail.scheme.expert.spProFollowerNum,style: TextStyle(fontSize: sp(10),color: Color(0xFF999999)),)
                          ],
                        ),
                      ),
                    ],
                  ),
                  SizedBox(height: 3,),
                  Text(SPClassStringUtils.spFunMaxLength(widget.info?.intro??'',length: 50),style: TextStyle(fontSize: sp(12),color: Color(0xFF666666))),
                ],
              )
          ),

          (widget.info?.spProCorrectRate30Day==null|| widget.info?.spProCorrectRate30Day=='0')?Container():Image.asset(
            SPClassImageUtil.spFunGetImagePath("ic_rate_${widget.info?.spProCorrectRate30Day}"), //
            width: MediaQuery.of(context).size.width,
          )
        ],
      ),
    );
  }

  Widget chartWidget(){
    return  Container(
      padding: EdgeInsets.all(width(10)),
      margin: EdgeInsets.only(left: width(13),right: width(13),top: height(8)),
      decoration: BoxDecoration(
          color: Colors.white,
          boxShadow:[
            BoxShadow(
              offset: Offset(2,5),
              color: Color(0x0D000000),
              blurRadius:width(6,),),
            BoxShadow(
              offset: Offset(-5,1),
              color: Color(0x0D000000),
              blurRadius:width(6,),
            )
          ],
          borderRadius: BorderRadius.circular(width(7))
      ),
      width: MediaQuery.of(context).size.width,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Container(
            child: TabBar(
              isScrollable: false,
              indicatorColor: Colors.transparent,
              controller: _tabController,
              onTap: (v){
                index =v;
                setState(() {
                });
                if(index==2&&leagueData==null){
                  SPClassApiManager.spFunGetInstance().spFunLeagueInfo(queryParameters: {"expert_uid":widget.info!.spProUserId,"league_name":selectLeague},
                      context:context,spProCallBack: SPClassHttpCallBack(
                          spProOnSuccess: (info){
                            leagueData= info.spProLeaguesList;
                            setState(() {
                            });
                          },onError: (e){},spProOnProgress: (v){}
                      ));
                }
              },
              tabs: tabBarList.map((e) {
                return Column(
                  children: <Widget>[
                    Container(
                      child: Text(e,style: TextStyle(color:index==tabBarList.indexOf(e)?MyColors.main1:MyColors.grey_66,fontSize: sp(14)),),
                    ),
                    SizedBox(height: width(3),),
                    index==tabBarList.indexOf(e)?Image.asset(
                      SPClassImageUtil.spFunGetImagePath("sanjiao"),
                      height: width(4),
                    ):Container(height:width(4),),
                  ],
                );
              }).toList(),
            ),
          ),
          Container(
            width: MediaQuery.of(context).size.width,
            height: 0.4,
            color: Colors.grey[300],
          ),
          index==0?recentStatusWidget():index==1?hitRateWidget():leaguesWidget(),
        ],

      ),
    );
  }

  Widget expertScheme(){
    return spProSchemeList.isEmpty?SizedBox():  Container(
      margin: EdgeInsets.only(left: width(13),right:  width(13),top:width(8) ),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(width(7)),
        boxShadow:[
          BoxShadow(
            offset: Offset(2,5),
            color: Color(0x0D000000),
            blurRadius:width(6,),),
          BoxShadow(
            offset: Offset(-5,1),
            color: Color(0x0D000000),
            blurRadius:width(6,),
          )
        ],
      ),
      width: MediaQuery.of(context).size.width,

      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Container(
            height: height(35),
            padding: EdgeInsets.only(left: width(13),right: width(13)),
            decoration: BoxDecoration(
                border: Border(bottom: BorderSide(width: 0.4,color: Colors.grey[300]!))
            ),
            child: Row(
              children: <Widget>[
                Container(
                  width: height(4),
                  height: height(14),
                  decoration: BoxDecoration(
                      color: Color(0xFFDE3C31),
                      borderRadius: BorderRadius.circular(100)
                  ),
                ),
                SizedBox(width: 4,),
                Text("正在推荐",style: TextStyle(fontWeight: FontWeight.w500,fontSize: width(15)),),

              ],
            ),
          ),
          ListView.builder(
              physics: NeverScrollableScrollPhysics(),
              shrinkWrap: true,
              padding: EdgeInsets.only(bottom: width(5)),
              itemCount: spProSchemeList.length,
              itemBuilder: (c,index){
                var item=spProSchemeList[index];
                return SPClassSchemeItemView(item,spProCanClick: false,spProShowLine:spProSchemeList.length>(index+1));
              })
        ],
      ),
    );
  }

  Widget historyScheme(){
    return spProSchemeHistory.isEmpty?SizedBox():  Container(
      margin: EdgeInsets.only(left: width(13),right:  width(13),top:width(8) ),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(width(7)),
        boxShadow:[
          BoxShadow(
            offset: Offset(2,5),
            color: Color(0x0D000000),
            blurRadius:width(6,),),
          BoxShadow(
            offset: Offset(-5,1),
            color: Color(0x0D000000),
            blurRadius:width(6,),
          )
        ],
      ),
      width: MediaQuery.of(context).size.width,

      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Container(
            height: height(35),
            padding: EdgeInsets.only(left: width(13),right: width(13)),
            decoration: BoxDecoration(
                border: Border(bottom: BorderSide(width: 0.4,color: Colors.grey[300]!))
            ),
            child: Row(
              children: <Widget>[
                Container(
                  width: height(4),
                  height: height(14),
                  decoration: BoxDecoration(
                      color: Color(0xFFDE3C31),
                      borderRadius: BorderRadius.circular(100)
                  ),
                ),
                SizedBox(width: 4,),
                Text("历史推荐",style: TextStyle(fontWeight: FontWeight.w600,fontSize: width(15)),),

              ],
            ),
          ),
          ListView.builder(
              physics: NeverScrollableScrollPhysics(),
              shrinkWrap: true,
              padding: EdgeInsets.only(bottom: width(5)),
              itemCount: spProSchemeHistory.length,
              itemBuilder: (c,index){
                var item=spProSchemeHistory[index];
                return SPClassSchemeItemView(item,spProCanClick: false,spProShowLine:spProSchemeHistory.length>(index+1));
              })
        ],
      ),
    );
  }

  void spFunOnRefreshSelf() {
    SPClassApiManager.spFunGetInstance().spFunSchemeList(queryParameters: {"expert_uid":widget.info!.spProUserId,"page":"1","fetch_type":"expert"},spProCallBack: SPClassHttpCallBack<SPClassSchemeListEntity>(
        spProOnSuccess: (list){
          list.spProSchemeList!.forEach((itemx){
            if(itemx.spProIsOver=="1"){
             spProSchemeHistory.add(itemx);
            }else{
              spProSchemeList.add(itemx);
            }
          });
          if(mounted){
            setState(() {
         });
          }
        },
        onError: (value){
        },spProOnProgress: (v){}
    ));
  }

  Future spFunOnLoadSelf() async{
    page++;
    SPClassApiManager.spFunGetInstance().spFunSchemeList(queryParameters: {"expert_uid":widget.info!.spProUserId,"page":"$page","fetch_type":"expert"},spProCallBack: SPClassHttpCallBack<SPClassSchemeListEntity>(
        spProOnSuccess: (list){
          list.spProSchemeList!.forEach((itemx){
            if(itemx.spProIsOver=="1"){
              spProSchemeHistory.add(itemx);
            }
            // else{
            //   spProSchemeList.add(itemx);
            // }
          });
          if(mounted){
            setState(() {
            });
          }
        },
        onError: (value){
        }
    ));
  }


  void spFunGetRecentReport() {
      spProDates=  SPClassMatchDataUtils.spFunCalcDateCount(widget.info!.spProLast10Result!);
      spProDates!.sort((left,right)=>right.compareTo(left));
      spProDates!.forEach((item){
        spProChartData.add(SPClassChartData((SPClassMatchDataUtils.spFunCalcCorrectRateByDate(widget.info!.spProLast10Result!,item)*100).roundToDouble(),"近"+
            "${item.toString()}"+
                "场"));
       });
      if(spProChartData.length==1){
        spProChartData.add(SPClassChartData(spProChartData[0].y,""));
      }
      setState(() {});
  }

  List<SPClassChartData> spFunGetLeagueRecent(String? recent10){
    if(recent10==null){
      return [];
    }
    List<SPClassChartData> data=[];
    List list=  SPClassMatchDataUtils.spFunCalcDateCount(recent10);
    list.sort((left,right)=>right.compareTo(left));
    list.forEach((item){
      data.add(SPClassChartData((SPClassMatchDataUtils.spFunCalcCorrectRateByDate(recent10,item)*100).roundToDouble(),"近"+
          "${item.toString()}"+
          "场"));
    });
    if(data.length==1){
      data.add(SPClassChartData(data[0].y,""));
    }
    return data;
  }

  Widget spFunBuildCharts() {
    return Container(
      height:width(150),
      child:SfCartesianChart(
        plotAreaBorderWidth: 0,
        margin: EdgeInsets.only(right: 20,top: 10,bottom: 10),
        onTooltipRender: (TooltipArgs args) {
          final NumberFormat format = NumberFormat.decimalPattern();
          var text=  format.format(args.dataPoints![args.pointIndex!.toInt()].y).toString();
          SPClassLogUtils.spFunPrintLog("text：${text.toString()}");
        },
        title: ChartTitle(text: ""),
        legend: Legend(
            isVisible: false,
            overflowMode: LegendItemOverflowMode.wrap),
        primaryXAxis: CategoryAxis(
            labelStyle:TextStyle(fontSize: sp(12)),
            labelPlacement: LabelPlacement.onTicks,
            majorGridLines: MajorGridLines(width: 0.4)),
        primaryYAxis: NumericAxis(
            maximum: 100,
            labelFormat: '{value}%',
            interval: 25,
            axisLine: AxisLine(width: 0),
            labelStyle: TextStyle(fontSize: sp(12)),
            majorTickLines: MajorTickLines(color: Colors.transparent)),
        series: <AreaSeries<SPClassChartData, String>>[
          AreaSeries<SPClassChartData, String>(
              animationDuration: 2500,
              enableTooltip: true,
              gradient:LinearGradient(colors:[Colors.white.withOpacity(0.5),Colors.red.withOpacity(0.5)],begin: Alignment.bottomCenter,end: Alignment.topCenter),
              dataSource: spProChartData,
              borderColor: Colors.red,
              borderWidth: 1,
              xValueMapper: (SPClassChartData sales, _) => sales.x,
              yValueMapper: (SPClassChartData sales, _) => sales.y,
              name: "近期胜率",
              markerSettings: MarkerSettings(
                  isVisible: true, color:Colors.red,borderColor: Colors.white)),


        ],
        tooltipBehavior: TooltipBehavior(enable: true,color: Colors.red,borderColor:Colors.cyan ),
      ),

    );
  }

  //  近期状态
  Widget recentStatusWidget(){
    return Column(
      children: <Widget>[
        spProChartData.isEmpty? SizedBox():
        spFunBuildCharts(),
        SizedBox(height: 7,),
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Expanded(
              child: Container(
                height: width(47),
                decoration: BoxDecoration(
                    color: Color(0xFFF6F6F6),
                    borderRadius: BorderRadius.circular(width(3))
                ),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    Text("${(double.tryParse(widget.info?.spProRecentProfitSum??'0')!*100).toStringAsFixed(0)}%",style:TextStyle(color: Color(0xFFE3494B),fontSize: sp(16),fontWeight: FontWeight.w600,)),
                    Text("近10场回报率",style: TextStyle(fontSize: sp(10),color: Color(0xFF666666)),),
                  ],
                ),
              ),
            ),
            SizedBox(width: width(7),),
            Expanded(
              child:Container(
                height: width(47),
                decoration: BoxDecoration(
                    color: Color(0xFFF6F6F6),
                    borderRadius: BorderRadius.circular(width(3))
                ),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    Text("${widget.info!.spProRecentAvgOdds}",style: TextStyle(color: Color(0xFFE3494B), fontSize: sp(16),fontWeight: FontWeight.w600,)),
                    Text("SP均值",style: TextStyle(fontSize: sp(10),color: Color(0xFF666666)),),

                  ],
                ),
              ) ,
            ),
            SizedBox(width: width(7),),
            Expanded(
              child: Container(
                height: width(47),
                decoration: BoxDecoration(
                    color: Color(0xFFF6F6F6),
                    borderRadius: BorderRadius.circular(width(3))
                ),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    Text("${widget.info!.spProCurrentRedNum}",style: TextStyle(color: Color(0xFFE3494B), fontSize: sp(16),fontWeight: FontWeight.w600,)),
                    Text("最近连红",style: TextStyle(fontSize: sp(10),color: Color(0xFF666666)),),

                  ],
                ),
              ),
            ),
            SizedBox(width: width(7),),
            Expanded(
              child: Container(
                height: width(47),
                decoration: BoxDecoration(
                    color: Color(0xFFF6F6F6),
                    borderRadius: BorderRadius.circular(width(3))
                ),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    Text("${widget.info!.spProMaxRedNum}",style: TextStyle(color: Color(0xFFE3494B), fontSize: sp(16),fontWeight: FontWeight.w600,),),
                    Text("历史最高连红",style: TextStyle(fontSize: sp(10),color: Color(0xFF666666)),),

                  ],
                ),
              ),
            )
          ],
        ),
      ],
    );
  }

//  命中率
  Widget hitRateWidget(){
    return widget.info?.spProHit==null? Center(
      child: SPClassNoDataView(height: width(200),),
    ):Container(
      padding: EdgeInsets.only(left: width(20),right:  width(20),top:  width(10),),
      child: Column(
        children: <Widget>[
          // 近七天
          widget.info?.spProHit?.spProWeek?.spProCount==0?Container():Column(
            children: <Widget>[
              Row(
                children: <Widget>[
                  Text('近7天',style: TextStyle(color: MyColors.grey_33,fontSize: sp(12)),),
                  Text('(${widget.info?.spProHit?.spProWeek?.spProCount}场)',style: TextStyle(color: MyColors.grey_99,fontSize: sp(12)),),
                  Expanded(
                    child: SizedBox(),
                  ),
                  Text('${widget.info?.spProHit?.spProWeek?.spProRed}红',style: TextStyle(color: MyColors.main1,fontSize: sp(12)),),
                  Text('${widget.info?.spProHit?.spProWeek?.spProGo}走',style: TextStyle(color: Colors.green,fontSize: sp(12)),),
                  Text('${widget.info?.spProHit?.spProWeek?.spProBlack}黑',style: TextStyle(color: MyColors.grey_99,fontSize: sp(12)),),
                ],
              ),
              SizedBox(height: width(8),),
              linearWidget(widget.info?.spProHit?.spProWeek?.spProCount??0,widget.info?.spProHit?.spProWeek?.spProRed??0,widget.info?.spProHit?.spProWeek?.spProGo??0,widget.info?.spProHit?.spProWeek?.spProBlack??0),
              SizedBox(height: width(10),),
            ],
          ),
          // 近30天
          widget.info?.spProHit?.spProMonth?.spProCount==0?Container():Column(
            children: <Widget>[
              Row(
                children: <Widget>[
                  Text('近30天',style: TextStyle(color: MyColors.grey_33,fontSize: sp(12)),),
                  Text('(${widget.info?.spProHit?.spProMonth?.spProCount}场)',style: TextStyle(color: MyColors.grey_99,fontSize: sp(12)),),
                  Expanded(
                    child: SizedBox(),
                  ),
                  Row(
                    children: <Widget>[
                      Text('${widget.info?.spProHit?.spProMonth?.spProRed}红',style: TextStyle(color: MyColors.main1,fontSize: sp(12)),),
                      Text('${widget.info?.spProHit?.spProMonth?.spProGo}走',style: TextStyle(color: Colors.green,fontSize: sp(12)),),
                      Text('${widget.info?.spProHit?.spProMonth?.spProBlack}黑',style: TextStyle(color: MyColors.grey_99,fontSize: sp(12)),),],
                  )
                ],
              ),
              SizedBox(height: width(8),),
              linearWidget(widget.info?.spProHit?.spProMonth?.spProCount??0,widget.info?.spProHit?.spProMonth?.spProRed??0,widget.info?.spProHit?.spProMonth?.spProGo??0,widget.info?.spProHit?.spProMonth?.spProBlack??0),
              SizedBox(height: width(10),),
            ],
          ),
          // 全周期
          widget.info?.spProHit?.spProAll?.spProCount==0?Container():Column(
            children: <Widget>[
              Row(
                children: <Widget>[
                  Text('全周期',style: TextStyle(color: MyColors.grey_33,fontSize: sp(12)),),
                  Text('(${widget.info?.spProHit?.spProAll?.spProCount}场)',style: TextStyle(color: MyColors.grey_99,fontSize: sp(12)),),
                  Expanded(
                    child: SizedBox(),
                  ),
                  Row(
                    children: <Widget>[
                      Text('${widget.info?.spProHit?.spProAll?.spProRed}红',style: TextStyle(color: MyColors.main1,fontSize: sp(12)),),
                      Text('${widget.info?.spProHit?.spProAll?.spProGo}走',style: TextStyle(color: Colors.green,fontSize: sp(12)),),
                      Text('${widget.info?.spProHit?.spProAll?.spProBlack}黑',style: TextStyle(color: MyColors.grey_99,fontSize: sp(12)),),],
                  )
                ],
              ),
              SizedBox(height: width(8),),
              linearWidget(widget.info?.spProHit?.spProAll?.spProCount??0,widget.info?.spProHit?.spProAll?.spProRed??0,widget.info?.spProHit?.spProAll?.spProGo??0,widget.info?.spProHit?.spProAll?.spProBlack??0)
            ],
          ),
        ],
      ),
    );
  }

  Widget linearWidget(int all,int red,int go,int black){
    return all==0?Container():Column(
      children: <Widget>[
        Row(
          children: <Widget>[
            // 红
            Expanded(
              flex:getPercent(red,all),
              child: Container(
                // margin: EdgeInsets.only(right: width(4)),
                alignment: Alignment.center,
                decoration: BoxDecoration(
                  color: Color(0xFFDE3C31),
                  // borderRadius: BorderRadius.horizontal(left:Radius.circular(300) )
                ),
                height: width(7),
              ),
            ),
            // 走
            Expanded(
              flex:getPercent(go,all)<10&&go!=0?2:getPercent(go,all),  //最小是2,不然显示不出
              child: Container(
                // margin: EdgeInsets.only(right: width(4)),
                color: Colors.green,
                alignment: Alignment.center,
                height: width(7),
              ),
            ),
            // 黑
            Expanded(
              flex:getPercent(black,all)<10&&black!=0?2:getPercent(black,all),
              child: Container(
                alignment: Alignment.center,
                decoration: BoxDecoration(
                  color: MyColors.grey_99,
                  // borderRadius: BorderRadius.horizontal(right:Radius.circular(150) )
                ),
                height: width(7),
              ),
            ),
          ],
        ),
        Row(
          children: <Widget>[
            Visibility(
              child: Expanded(
                  flex:getPercent(red,all),
                  child: Text('${getPercent(red,all)}%',textAlign: TextAlign.center,style: TextStyle(fontSize: sp(10),color: MyColors.main1),)
              ),
              visible: getPercent(red,all)!=0,
            ),
            Visibility(
              child: Expanded(
                  flex:getPercent(go,all)<10&&black!=0?10:getPercent(go,all), //最小是10
                  child: Text('${getPercent(go,all)}%',textAlign: TextAlign.center,style: TextStyle(fontSize: sp(10),color: MyColors.main1),)
              ),
              visible: getPercent(go,all)!=0,
            ),
            Visibility(
              child: Expanded(
                  flex:getPercent(black,all)<10&&black!=0?10:getPercent(black,all), //最小是10
                  child: Text('${100-getPercent(red,all)-getPercent(go,all)}%',textAlign: TextAlign.center,style: TextStyle(fontSize: sp(10),color: MyColors.main1),)
              ),
              visible: getPercent(black,all)!=0,
            ),
          ],
        )
      ],
    );
  }

//  联赛胜率
  Widget leaguesWidget(){
    return leagueData==null?Center(child: SPClassNoDataView(height: width(250),)): Container(
      margin: EdgeInsets.only(top: width(16)),
      child: Column(
        children: <Widget>[
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              GestureDetector(
                onTap: (){
                  SPClassNavigatorUtils.spFunPushRoute(context,
                      SPClassLeaguePage(selectLeagueName: selectLeague,expertId: widget.info!.spProUserId,selectTime: selectTime,)
                  ).then((value){
                    if(value!=null){
                      selectLeague =value.toString();
                      SPClassApiManager.spFunGetInstance().spFunLeagueInfo(queryParameters: {"expert_uid":widget.info!.spProUserId,"league_name":selectLeague},
                          context:context,spProCallBack: SPClassHttpCallBack(
                              spProOnSuccess: (info){
                                leagueData= info.spProLeaguesList;
                                setState(() {
                                });
                              },onError: (e){},spProOnProgress: (v){}
                          ));
                    }
                  });
                },
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    Text('赛事筛选',style: TextStyle(fontSize: sp(14),color: Color(0xFF333333)),),
                    SPClassExpandIcon(
                      padding: EdgeInsets.zero,
                      isExpanded: false,
                      color: Colors.grey[300],
                    ),
                    //ic_btn_down
                  ],
                ),
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.end,
                children: leaguesTimeList.map((e) {
                  return InkWell(
                    onTap: (){
                      selectTime = e;
                      setState(() {
                      });
                    },
                    child: Container(
                      width: width(54),
                      height: width(20),
                      alignment: Alignment.center,
                      margin: EdgeInsets.only(left: width(16)),
                      decoration: BoxDecoration(
                          color:selectTime==e?MyColors.main1: Color(0xFFF2F2F2),
                          borderRadius: BorderRadius.circular(4)
                      ),
                      child: Text(e,style: TextStyle(fontSize: sp(12),color:selectTime==e?Colors.white:MyColors.grey_99),),
                    ),
                  );
                }).toList(),
              ),

            ],
          ),
          leaguesItem(selectTime=='近7天'?leagueData!.spProWeek:selectTime=='近30天'?leagueData!.spProMonth:leagueData!.spProAll),

        ],
      ),
    );
  }

  Widget leaguesItem(List<SPClassHitDetail> ?list){
    return list!.isEmpty?SPClassNoDataView(height: width(200),): Column(
      children: (selectLeague==''?list.take(5):list).map((e) {
        return Row(
          children: <Widget>[
            Expanded(
              child: GestureDetector(
                behavior: HitTestBehavior.translucent,
                onTap: (){
                  SPClassNavigatorUtils.spFunPushRoute(context, SPClassExpertLeagueDetail(nickName: widget.info!.spProNickName,expertUid:widget.info!.spProUserId,leagueName: e.spProLeagueName,index: leaguesTimeList.indexOf(selectTime),));
                },
                child: Container(
                  margin: EdgeInsets.only(top: width(5),left: width(1),right: width(1)),
                  padding: EdgeInsets.symmetric(horizontal: width(16),vertical: width(8)),
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(4),
                    boxShadow:[
                      BoxShadow(
                        offset: Offset(0,0),
                        color: Color.fromRGBO(0, 0, 0, 0.16),
                        blurRadius:width(1,),),
                    ],
                  ),
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: <Widget>[
                      Container(
                        width: width(60),
                        child: Text(e.spProLeagueName??'',style: TextStyle(fontSize: sp(12),color: MyColors.grey_66),maxLines: 1,overflow: TextOverflow.ellipsis,),
                      ),
                      Expanded(
                        child:Container(
                          margin: EdgeInsets.only(right: width(20),),
                          child: Column(
                            children: <Widget>[
                              Row(
                                children: <Widget>[
                                  Text('场数:${e.spProCount}',style: TextStyle(fontSize: sp(12),color: MyColors.grey_66)),
                                  Expanded(
                                    child: SizedBox(),
                                  ),
                                  Text('${e.spProRed}红',style: TextStyle(fontSize: sp(12),color: MyColors.main1)),
                                  Text('${e.spProGo}走',style: TextStyle(fontSize: sp(12),color: MyColors.green)),
                                  Text('${e.spProBlack}黑',style: TextStyle(fontSize: sp(12),color: MyColors.grey_99)),

                                ],
                              ),
                              Row(
                                children: <Widget>[
                                  // 红
                                  Expanded(
                                    flex:getPercent(e.spProRed??0,e.spProCount??0),
                                    child: Container(
                                      // margin: EdgeInsets.only(right: width(4)),
                                      alignment: Alignment.center,
                                      decoration: BoxDecoration(
                                        color: Color(0xFFDE3C31),
                                        // borderRadius: BorderRadius.horizontal(left:Radius.circular(300) )
                                      ),
                                      height: width(8),
                                    ),
                                  ),
                                  // 走
                                  Expanded(
                                    flex:getPercent(e.spProGo??0,e.spProCount??0)<10&&e.spProGo!=0?2:getPercent(e.spProGo??0,e.spProCount??0),  //最小是2,不然显示不出
                                    child: Container(
                                      // margin: EdgeInsets.only(right: width(4)),
                                      color: MyColors.green,
                                      alignment: Alignment.center,
                                      height: width(8),
                                    ),
                                  ),
                                  // 黑
                                  Expanded(
                                    flex:getPercent(e.spProBlack??0,e.spProCount??0),
                                    child: Container(
                                      alignment: Alignment.center,
                                      decoration: BoxDecoration(
                                        color: MyColors.grey_99,
                                        // borderRadius: BorderRadius.horizontal(right:Radius.circular(150) )
                                      ),
                                      height: width(8),
                                    ),
                                  ),
                                ],
                              ),

                            ],
                          ),
                        ),
                      ),
                      Container(
                        width: width(50),
                        alignment: Alignment.centerRight,
                        child: Text('${getPercent(e.spProRed??0,e.spProCount??0)}% >',style: TextStyle(fontSize: sp(12),color: MyColors.main1),),
                      ),
                    ],
                  ),
                ),
              ),
            )
          ],
        );
      }).toList(),
    );
  }

  getPercent(int count,int all){
    if(all==0||count==0){
      return 0;
    }
    return ((count/all)*100).floor();
  }

}

class SPClassChartData {
  SPClassChartData( this.y,this.x,);
   String x;
   double y;
   String z="xsdsadsa";
}



